<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>png++: png::generator&lt; pixel, pixgen, info_holder, interlacing_supported &gt; Class Template Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">png++
   &#160;<span id="projectnumber">0.2.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="namespacepng.html">png</a>      </li>
      <li class="navelem"><a class="el" href="classpng_1_1generator.html">generator</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pro-types">Protected Types</a> &#124;
<a href="#pro-methods">Protected Member Functions</a>  </div>
  <div class="headertitle">
<div class="title">png::generator&lt; pixel, pixgen, info_holder, interlacing_supported &gt; Class Template Reference</div>  </div>
</div><!--header-->
<div class="contents">
<!-- doxytag: class="png::generator" --><!-- doxytag: inherits="png::streaming_base" -->
<p>Pixel generator class template.  
 <a href="classpng_1_1generator.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="generator_8hpp_source.html">generator.hpp</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for png::generator&lt; pixel, pixgen, info_holder, interlacing_supported &gt;:</div>
<div class="dyncontent">
 <div class="center">
  <img src="classpng_1_1generator.png" usemap="#png::generator&lt; pixel, pixgen, info_holder, interlacing_supported &gt;_map" alt=""/>
  <map id="png::generator&lt; pixel, pixgen, info_holder, interlacing_supported &gt;_map" name="png::generator&lt; pixel, pixgen, info_holder, interlacing_supported &gt;_map">
<area href="classpng_1_1streaming__base.html" title="A base class template for consumer and generator classes. Provides default reset() method implementat..." alt="png::streaming_base&lt; pixel, info_holder &gt;" shape="rect" coords="0,0,394,24"/>
</map>
 </div></div>

<p><a href="classpng_1_1generator-members.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memTemplParams" colspan="2">template&lt;typename ostream &gt; </td></tr>
<tr><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classpng_1_1generator.html#ab96a8e8e7050afddb307141d7cabb5eb">write</a> (ostream &amp;stream)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Writes an image to the stream.  <a href="#ab96a8e8e7050afddb307141d7cabb5eb"></a><br/></td></tr>
<tr><td colspan="2"><h2><a name="pro-types"></a>
Protected Types</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">typedef <a class="el" href="classpng_1_1streaming__base.html">streaming_base</a>&lt; pixel, <br class="typebreak"/>
info_holder &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classpng_1_1generator.html#afd0ec501ad497cd64b38d9edfb4a0ab6">base</a></td></tr>
<tr><td colspan="2"><h2><a name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classpng_1_1generator.html#a9580193ea493f8b9d289caf349898395">generator</a> (<a class="el" href="classpng_1_1image__info.html">image_info</a> &amp;<a class="el" href="classpng_1_1info.html">info</a>)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructs a generator object using passed <a class="el" href="classpng_1_1image__info.html" title="Holds information about PNG image.">image_info</a> object to store image information.  <a href="#a9580193ea493f8b9d289caf349898395"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classpng_1_1generator.html#a45d4289aaa3bffe7ae8065cb7c28220a">generator</a> (size_t width, size_t height)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructs a generator object prepared to generate an image of specified width and height.  <a href="#a45d4289aaa3bffe7ae8065cb7c28220a"></a><br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><h3>template&lt;typename pixel, class pixgen, class info_holder = def_image_info_holder, bool interlacing_supported = false&gt;<br/>
class png::generator&lt; pixel, pixgen, info_holder, interlacing_supported &gt;</h3>

<p>Pixel generator class template. </p>
<p>Used as a base class for custom pixel generator classes as well as inside image class implementation to write pixels from the pixel buffer.</p>
<p>A usage example can be found in <code>example/pixel_generator.cpp</code>.</p>
<p>Encapsulates PNG image writing procedure. In order to create a custom pixel generator use CRTP trick:</p>
<div class="fragment"><pre class="fragment"> <span class="keyword">class </span>pixel_generator
     : <span class="keyword">public</span> png::<a class="code" href="classpng_1_1generator.html#a9580193ea493f8b9d289caf349898395" title="Constructs a generator object using passed image_info object to store image information.">generator</a>&lt; pixel, pixel_generator &gt;
 {
     ...
 };
</pre></div><p>Your pixel generator class should implement <code>get_next_row()</code> method and <code><a class="el" href="classpng_1_1streaming__base.html#a5e2700341b10eecb7086ef3cf715c438">reset()</a></code> method (optional). Their signatures are as follows:</p>
<div class="fragment"><pre class="fragment"> <a class="code" href="namespacepng.html#ac0e0e2e09bdd9a287618bfdc5f31ca52">png::byte</a>* get_next_row(<span class="keywordtype">size_t</span> pos);
 <span class="keywordtype">void</span> <a class="code" href="classpng_1_1streaming__base.html#a5e2700341b10eecb7086ef3cf715c438">reset</a>(<span class="keywordtype">size_t</span> pass);
</pre></div><p>The <code>get_next_row()</code> method is called every time a new row of image data is needed by the writer. The position of the row being written is passed as <code>pos</code> parameter. The <code>pos</code> takes values from <code>0</code> to <code></code> &lt;image_height&gt;-1 inclusively. The method should return the starting address of a row buffer storing an appropriate amount of pixels (i.e. the width of the image being written). The address should be casted to <a class="el" href="namespacepng.html#ac0e0e2e09bdd9a287618bfdc5f31ca52">png::byte</a>* pointer type using <code>reinterpret_cast&lt;&gt;</code> or a C-style cast.</p>
<p>The optional <code><a class="el" href="classpng_1_1streaming__base.html#a5e2700341b10eecb7086ef3cf715c438">reset()</a></code> method is called every time the new pass of interlaced image processing starts. The number of interlace pass is avaiable as the only parameter of the method. For non-interlaced images the method is called once prior to any calls to <code>get_next_row()</code>. The value of <code>0</code> is passed for the <code>pass</code> number. You do not have to implement this method unless you are going to support interlaced image generation.</p>
<p>An optional template parameter <code>info_holder</code> encapsulated <a class="el" href="classpng_1_1image__info.html" title="Holds information about PNG image.">image_info</a> storage policy. Please refer to consumer class documentation for the detailed description of this parameter.</p>
<p>An optional <code>bool</code> template parameter <code>interlacing_supported</code> specifies whether writing interlacing images is supported by your generator class. It defaults to <code>false</code>. An attempt to write an interlaced image will result in throwing <code>std::logic_error</code>.</p>
<p>In order to fully support interlacing specify <code>true</code> for <code>interlacing_supported</code> parameter and implement <code><a class="el" href="classpng_1_1streaming__base.html#a5e2700341b10eecb7086ef3cf715c438">reset()</a></code> method. You _must_ generate the same pixels for every pass to get the correct PNG image output.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classpng_1_1image.html" title="Class template to represent PNG image.">image</a>, <a class="el" href="classpng_1_1consumer.html" title="Pixel consumer class template.">consumer</a> </dd></dl>
</div><hr/><h2>Member Typedef Documentation</h2>
<a class="anchor" id="afd0ec501ad497cd64b38d9edfb4a0ab6"></a><!-- doxytag: member="png::generator::base" ref="afd0ec501ad497cd64b38d9edfb4a0ab6" args="" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename pixel, class pixgen, class info_holder = def_image_info_holder, bool interlacing_supported = false&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">typedef <a class="el" href="classpng_1_1streaming__base.html">streaming_base</a>&lt; pixel, info_holder &gt; <a class="el" href="classpng_1_1generator.html">png::generator</a>&lt; pixel, pixgen, info_holder, interlacing_supported &gt;::<a class="el" href="classpng_1_1generator.html#afd0ec501ad497cd64b38d9edfb4a0ab6">base</a><code> [protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

</div>
</div>
<hr/><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="a9580193ea493f8b9d289caf349898395"></a><!-- doxytag: member="png::generator::generator" ref="a9580193ea493f8b9d289caf349898395" args="(image_info &amp;info)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename pixel, class pixgen, class info_holder = def_image_info_holder, bool interlacing_supported = false&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classpng_1_1generator.html">png::generator</a>&lt; pixel, pixgen, info_holder, interlacing_supported &gt;::<a class="el" href="classpng_1_1generator.html">generator</a> </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classpng_1_1image__info.html">image_info</a> &amp;&#160;</td>
          <td class="paramname"><em>info</em></td><td>)</td>
          <td><code> [inline, explicit, protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Constructs a generator object using passed <a class="el" href="classpng_1_1image__info.html" title="Holds information about PNG image.">image_info</a> object to store image information. </p>

</div>
</div>
<a class="anchor" id="a45d4289aaa3bffe7ae8065cb7c28220a"></a><!-- doxytag: member="png::generator::generator" ref="a45d4289aaa3bffe7ae8065cb7c28220a" args="(size_t width, size_t height)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename pixel, class pixgen, class info_holder = def_image_info_holder, bool interlacing_supported = false&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classpng_1_1generator.html">png::generator</a>&lt; pixel, pixgen, info_holder, interlacing_supported &gt;::<a class="el" href="classpng_1_1generator.html">generator</a> </td>
          <td>(</td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>width</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>height</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td><code> [inline, protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Constructs a generator object prepared to generate an image of specified width and height. </p>

</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="ab96a8e8e7050afddb307141d7cabb5eb"></a><!-- doxytag: member="png::generator::write" ref="ab96a8e8e7050afddb307141d7cabb5eb" args="(ostream &amp;stream)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename pixel, class pixgen, class info_holder = def_image_info_holder, bool interlacing_supported = false&gt; </div>
<div class="memtemplate">
template&lt;typename ostream &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="classpng_1_1generator.html">png::generator</a>&lt; pixel, pixgen, info_holder, interlacing_supported &gt;::<a class="el" href="classpng_1_1generator.html#ab96a8e8e7050afddb307141d7cabb5eb">write</a> </td>
          <td>(</td>
          <td class="paramtype">ostream &amp;&#160;</td>
          <td class="paramname"><em>stream</em></td><td>)</td>
          <td><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Writes an image to the stream. </p>
<p>Essentially, this method constructs a writer object and instructs it to write the image to the stream. It handles writing interlaced images as long as your generator class supports this. </p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="generator_8hpp_source.html">generator.hpp</a></li>
</ul>
</div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Fri Jan 25 2013 14:10:10 for png++ by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
